<?php /*
	
*/ ?>
<?php include("system/config.inc.php");
$donotinclude = 1;
if(!isset($_SESSION['memberid'])){
	header("location:customerlogin.php");
	die();
}
// check customer basket is empty or not
$id=$_SESSION['memberid'];
if(isset($_SESSION['memberid']) && trim($_SESSION['memberid']!="")) {
$id = $_SESSION['memberid'];
$sqlbask="select * from tblcustomerbaskets where intcustomerid='$id'";
$resbask=$n02586916_db->select($sqlbask);
	if(count($resbask)==0) {
		header("location:cart.php");
		die();
	}
} else if(isset($_SESSION['custid']) && ($_SESSION['custid']!="")) {
$id= $_SESSION['custid'];
$sqlbask="select * from tblcustomerbaskets where intcustomerid='$id'";
$resbask=$n02586916_db->select($sqlbask);
	if(count($resbask)==0) {
		header("location:cart.php");
		die();
	}
}

			if(isset($_SESSION['memberid']) && ($_SESSION['memberid'])!="") {
				$custid=$_SESSION['memberid'];
			} else if(isset($_SESSION['custid']) && ($_SESSION['custid'])!="") {
				$custid= $_SESSION['custid'];
			}
			$sql="select * from tblcustomeradd where intcustomerid='$custid'";
			$res=$n02586916_db->select($sql);
			
			$paddress=stripslashes($res[0]['vardeliverystreetaddress']);
			$pcity=stripslashes($res[0]['vardeliverycity']);
			$pcode=stripslashes($res[0]['vardeliverypostcode']);
			$pstate=stripslashes($res[0]['vardeliverystate']);
			$pcont=stripslashes($res[0]['vardeliverycountry']);
			$addarr = explode(" ",$paddress,2);
				

			if($_REQUEST['a']=="1") {
			$houseno = mysql_real_escape_string($_REQUEST['houseno']);
			$add = mysql_real_escape_string($_REQUEST['address']);
			$city = mysql_real_escape_string($_REQUEST['city']);
			$code = mysql_real_escape_string($_REQUEST['code']);
			$state = mysql_real_escape_string($_REQUEST['state']);
			$con = mysql_real_escape_string($_REQUEST['country']);
				if (strlen($paddress)<1) {			
				// do insert for new address
					$sql_insert = "INSERT INTO `tblcustomeradd` (`intcustomerid`,`varcustomerstreetaddress`,`varcustomercity`,`varcustomerpostcode`,`varcustomerstate`,`varcustomercountry`,`vardeliverystreetaddress`,`vardeliverycity`,`vardeliverypostcode`,`vardeliverystate`,`vardeliverycountry`,`varbillingstreetaddress`,`varbillingcity`,`varbillingpostcode`,`varbillingstate`,`varbillingcountry`,`dtfinished`) VALUES ('$id', '$houseno $add', '$city', '$code', '$state', '$con', '$houseno $add', '$city', '$code', '$state', '$con', '$houseno $add', '$city', '$code', '$state', '$con', NOW())";
					$sql=$n02586916_db->insert($sql_insert);
				} else {
					$sql_upd ="UPDATE `tblcustomeradd` SET 
							`vardeliverystreetaddress` = '$houseno $add', 
							`vardeliverycity` = '$city',
							`vardeliverypostcode`='$code',
							`vardeliverystate`='$state',
							`vardeliverycountry`='$con' 
							WHERE `intcustomerid`='$id'";
					$sql=$n02586916_db->edit($sql_upd);
				}
				
				$sql="select * from tblcustomeradd where intcustomerid='$custid'";
				$res=$n02586916_db->select($sql);
				
				$paddress=stripslashes($res[0]['vardeliverystreetaddress']);
				$pcity=stripslashes($res[0]['vardeliverycity']);
				$pcode=stripslashes($res[0]['vardeliverypostcode']);
				$pstate=stripslashes($res[0]['vardeliverystate']);
				$pcont=stripslashes($res[0]['vardeliverycountry']);
				$addarr = explode(" ",$paddress,2);
			}
?>
<?php include("inc/head.inc.php");?>
<script language="javascript">
var shippingmethod=0;
var formfield;

function whichradio() {
	formfield=document.shippingselect.shipopt // formname and input names to be checked
	for(i=0;i<formfield.length;i++) {
		if (formfield[i].checked==true) { // identify selected radio button
			if (formfield[i].value=='0') {
				alert("Please Select Shipping Option.");
				return false;
			} else {
				shippingmethod=formfield[i].value
				return shippingmethod;
			}
		}
	}
}

function shipmethod() {
	if(shippingmethod==0) {
		alert("Please Select Shipping Option.");
		return false;
	} else {
		document.location="checkoutpayment.php?ship="+shippingmethod;
	}
}	

</script>
<body>
<table width="824" border="0" cellpadding="0" cellspacing="0"  align="center">
  
  <tr>
    <td class="headerclass"><?php include(INC."top.inc.php") ?></td>
  </tr>
  <tr>
    <td valign="top" class="maincontainer"><table width="100%" border="0" cellpadding="0" cellspacing="0">
      <tr><td valign="top"class="leftmenuback"><?php include(INC."left.inc.php") ?></td>
        <td valign="top">
		<table width="98%" border="0" align="center" cellpadding="0" cellspacing="5">
        <tr>
          <td width="100%" height="23" bgcolor="#000000" class="style1">&nbsp; Delivery Information </td>
        </tr>
		<tr>
		  <td height="23" align="right" valign="middle" class="staus"><img src="images/back.gif" onClick="history.go(-1);" border="0"/></td>
		  </tr>
		<tr>
          <td height="23" valign="middle" class="font">&nbsp; <span class="font">&nbsp;1&nbsp;&nbsp;confirm</span> | <span class="price">&nbsp;2&nbsp;&nbsp;postage</span> | <span class="font">&nbsp;3&nbsp;&nbsp;pay</span> | <span class="font">&nbsp;5&nbsp;&nbsp;Discount Codes</span> | <span class="font">&nbsp;5&nbsp;&nbsp;Order Confirmation</span></td>
	    </tr>
        <tr>
          <td align="center" class="aabold">
		  <table width="100%" border="0" cellpadding="0" cellspacing="2" class="proborder">
            <tr>
              <td height="23" class="search" bgcolor="#E9E9E9" style="border:1px solid #999999;" colspan="2">&nbsp;Shipping Address </td>
              </tr>
            <tr>
              <td width="71%" class="font">If the  <strong>Shipping Address</strong> shown right is incorrect or blank use the form below to update your shipping address and select a shipping method.<br /></td>
              <td width="29%" valign="top" class="fontsmall" align="left"><strong class="font">Shiping Address </strong></td>
            </tr>
            <tr>
              <td rowspan="2"></td>
              <td class="addressfont" align="left"><?php echo 
			   $paddress."<br>".
			   $pcity."<br>".
			   $pcode."<br>".
			   $pstate."<br>".
			   $pcont; ?></td>
            </tr>
          </table>
		  <br />
		 <form name="shippingselect" action="" method="post">
		  <table width="100%" border="0" cellpadding="0" cellspacing="2" class="proborder">
            <tr>
              <td height="23" class="search" bgcolor="#E9E9E9" style="border:1px solid #999999;" colspan="3">&nbsp;Shipping Method </td>
            </tr>
            
            <tr class="indexlef">
              <td height="23" align="center" class="font"><strong>Title</strong></td>
              <td align="center" class="font"><strong>Rate</strong></td>
              <td colspan="2" align="center" class="font"><strong>Please Select</strong></td>
              </tr>
			  <tr align="center">
              <td class="fontsmall">NO SHIPPING SELECTED</td>
              <td width="25%" class="fontsmall">PLEASE SELECT METHOD</td>
              <td width="38%"><input name="shipopt" id="shipopt" type="radio" value="0" checked="checked" onClick="whichradio();" /></td>
			  </tr>
			  <?php 
			  $shippin="";
				$sql10="select * from tblshippingmaster";
				$resship=$n02586916_db->select($sql10);
				if(count($resship)>0)
				{
					for($s=0;$s<count($resship);$s++) {
					$method=$resship[$s]['decshipcost'];
					$val=$resship[$s]['intid'];
					if(isset($val))	{
						$_SESSION['method']=$val;
					}
			?>
            <tr align="center">
              <td class="fontsmall"><?php echo $resship[$s]['vartitle'];?></td>
              <td width="25%" class="fontsmall"><?php echo $resship[$s]['decshipcost'];?></td>
              <td width="38%"><input name="shipopt" id="shipopt" type="radio" value="<?php echo $resship[$s]['intid'];?>" onClick="whichradio();" /></td>
            </tr>
		    <?php }} ?>
          </table>
		  </form>
<form name="editship" action="checkoutshiping.php?a=1" method="post">	
	<table width="100%" border="0" cellpadding="0" cellspacing="2" class="proborder">
  <tr>
    <td colspan="5" class="font">Please use the following form to update your shipping address to use for this order.</td>
    </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="font">House Number* </td>
    <td>:</td>
    <td><input name="houseno" type="text" class="feature_headingbg" id="houseno" value="<?php echo $addarr[0];?>" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="font">Street Name* </td>
    <td>:</td>
    <td><input name="address" type="text" class="feature_headingbg" id="address" value="<?php echo $addarr[1];?>" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="font">Town* </td>
    <td>:</td>
    <td><input name="city" type="text" class="feature_headingbg" id="city"  value="<?php echo $pcity; ?>"  /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="font">Postal Code* </td>
    <td>:</td>
    <td><input name="code" type="text" class="feature_headingbg" id="code"  value="<?php echo $pcode;?>" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="font">County </td>
    <td>:</td>
    <td><input name="state" type="text" class="feature_headingbg" id="state" value="<?php echo $pstate;?>"  /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td class="font">Country </td>
    <td>:</td>
    <td><input name="country" type="text" class="feature_headingbg" id="country" value="<?php echo $pcont; ?>"/></td>
    <td>&nbsp;</td>
  </tr>
  <tr class="fontsmall">
    <td colspan="5" align="center">&nbsp;</td>
  </tr>
  <tr class="fontsmall">
    <td colspan="5" align="center">
      <input name="Submit" type="submit" class="feature_headingbg" value="Update" />
	<br /><br /> 
	 Fields marked with a * are required items and must be completed before you can continue.
	</td>
    </tr>
</table>
		 </form><br /> 
		  <table width="100%" border="0" cellpadding="0" cellspacing="3" class="proborder">
      <tr>
        <td width="62%" align="left" class="msg1">Continue to confirm this order.</td>
		<td width="42%" align="right">
		<?php 
		if(isset($_REQUEST['shipopt']) && ($_REQUEST['shipopt'])!="")
		{
			$ship=$_REQUEST['shipopt'];
		}
		?>
		<?php if (strlen($paddress)>1 && strlen($pcity)>1 && strlen($pcode)>1) {?>
		<img src="images/continue.gif" style="cursor:hand;" border="0" onClick="return shipmethod();"  />
		<?php } ?>
		</td>
      </tr>
    </table>		  </td>
        </tr> 
      </table>		</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td><?php include "inc/bottom.inc.php"; ?></td>
  </tr>
</table>
</form>
</body>
</html>
